<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>createRef</title>
</head>

<body>
    <!-- 准备好一个容器 -->
    <div id="test"></div>


    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>

    <script type="text/babel">  /*此处一定要写babel*/
        //创建组件
        class Demo extends React.Component {

            // React.createRef调用后返回一个容器 该容器可以存储被ref标识的节点 该容器是专人专用的
            myRef=React.createRef();
            myRef2=React.createRef();
            state = {isHot:true};

            showInfo = () =>{
              alert(this.myRef.current.value)
            }

            showInfo2 = () =>{
              alert(this.myRef2.current.value)
            }
          

            render() {
                const {isHot} = this.state;
                return (
                    <div>
                         <input ref={this.myRef} type="text"  /><br/>
                        <button onClick={this.showInfo}>点击提示输入数据</button>
                        <input onBlur={this.showInfo2} ref={this.myRef2} type="text"  /><br/>
                    </div>
                )
            }
        }

        //渲染组件到页面
        ReactDOM.render(<Demo />, document.getElementById('test'));
    </script>
</body>

</html>